From 9285d9905927432f516f8c0efbdd47cafda40099 Mon Sep 17 00:00:00 2001 From: robertl Date: Sun, 21 Dec 2003 17:48:42 +0000 Subject: [PATCH] Add route reading code. --- gpsbabel/garmin.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/gpsbabel/garmin.c b/gpsbabel/garmin.c index 1b7efb6a9..2e6612a92 100644 --- a/gpsbabel/garmin.c +++ b/gpsbabel/garmin.c @@ -143,6 +143,57 @@ track_read(void) xfree(array); } +static +void +route_read(void) +{ + int32 nroutepts; + int i; + GPS_PWay *array; + + nroutepts = GPS_Command_Get_Route(portname, &array); + + fprintf(stderr, "Routes %d\n", nroutepts); +#if 1 + for (i = 0; i < nroutepts; i++) { + route_head *rte_head; + waypoint * wpt_tmp; + + if (array[i]->isrte) { + char *csrc = NULL; + /* What a horrible API has libjeeps for making this + * my problem. + */ + switch (array[i]->rte_prot) { + case 201: csrc = array[i]->rte_cmnt; break; + case 202: csrc = array[i]->rte_ident; break; + default: break; + } + rte_head = route_head_alloc(); + route_add_head(rte_head); + if (csrc) { + rte_head->rte_name = xstrdup(csrc); + } + ; + + } else { + if (array[i]->islink) { + continue; + } else { + wpt_tmp = xcalloc(sizeof (*wpt_tmp), 1); + wpt_tmp->latitude = array[i]->lat; + wpt_tmp->longitude = array[i]->lon; + wpt_tmp->shortname = array[i]->ident; + route_add_wpt(rte_head, wpt_tmp); + } + } + } +#else + GPS_Fmt_Print_Route(array, nroutepts, stderr); +#endif + +} + static void data_read(void) { @@ -153,8 +204,12 @@ data_read(void) case wptdata: waypt_read(); break; + case rtedata: + route_read(); + break; default: - fatal(MYNAME ": Routes are not yet supported\n"); + fatal(MYNAME ": Unknown objective %d.\n", + global_opts.objective); } } -- 2.30.2